Updated and Validated
[betaflight.git] / docs / development / Hardware Debugging.md
blob6577e9d07a87528604f91b7cce3c60646b6e6649
1 # Hardware debugging
3 The code can be compiled with debugging information, you can then upload a debug version to a board via a JLink/St-Link debug adapter and step through the code in your IDE.
5 More information about the necessary hardware and setting up the eclipse IDE can be found [here](Hardware%20Debugging%20in%20Eclipse.md)
7 A guide for visual studio can be found here:
8 http://visualgdb.com/tutorials/arm/st-link/
10 This video is also helpful in understanding the proces:
11 https://www.youtube.com/watch?v=kjvqySyNw20
13 ## Hardware
15 Various debugging hardware solutions exist, the Segger J-Link clones are cheap and are known to work on Windows with both the Naze and Olimexino platforms.
17 ### J-Link devices
19 Segger make excellent debuggers and debug software.
21 The Segger J-Link GDB server can be obtained from here.
23 http://www.segger.com/jlink-software.html
25 #### Segger J-Link EDU EDU version, for hobbyists and educational use.
27 ![Segger J-Link EDU](assets/hardware/j-link-edu.jpg)
29 https://www.segger.com/j-link-edu.html
31 #### USB-MiniJTAG J-Link JTAG/SWD Debugger/Emulator
33 http://www.hotmcu.com/usbminijtag-jlink-jtagswd-debuggeremula%E2%80%8Btor-p-29.html?cPath=3_25&zenid=fdefvpnod186umrhsek225dc10
35 ![THAOYU USB-MiniJTAG](assets/hardware/THAOYU-USB-MiniJTAG.jpg)
37 ##### ARM-JTAG-20-10 adapter
39 https://www.olimex.com/Products/ARM/JTAG/ARM-JTAG-20-10/
40 http://uk.farnell.com/jsp/search/productdetail.jsp?sku=2144328
42 ![OLIMEX ARM JTAG ADAPTER](assets/hardware/OLIMEX-ARM-JTAG-ADAPTER-2144328-40.jpg)
44 #### CJMCU-STM32 Singlechip Development Board Jlink Downloader Jlink ARM Programmer
46 ![CJMCU-STM32 Jlink ARM Programmer Front](assets/hardware/cjmcu-jlink-front.jpg)
48 ![CJMCU-STM32 Jlink ARM Programmer Back](assets/hardware/cjmcu-jlink-back.jpg)
50 http://www.goodluckbuy.com/cjmcu-stm32-singlechip-development-board-jlink-downloader-jlink-arm-programmer.html
53 ### STLink V2 devices
55 STLink V2 devices can be used too, via OpenOCD.
57 #### CEPark STLink V2
59 ![CEPark STLink V2](assets/hardware/cepark-stlink-v2-front.jpg)
61 http://www.goodluckbuy.com/cepark-stlink-st-link-v2-emulator-programmer-stm8-stm32-downloader.html
63 ## Compilation options
65 use `DEBUG=GDB` make argument.
67 You may find that if you compile all the files with debug information on that the program is too big to fit on the target device.  If this happens you have some options:
69 * Compile all files without debug information (`make clean`, `make ...`), then re-save or `touch` the files you want to be able to step though and then run `make DEBUG=GDB`.  This will then re-compile the files you're interested in debugging with debugging symbols and you will get a smaller binary file which should then fit on the device.
70 * You could use a development board such as an PORT103R, development boards often have more flash rom.
72 ## OSX
74 ### Install OpenOCD via Brew
76 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
78 brew install openocd
80 ### GDB debug server
82 #### J-Link
84 ##### Windows
86 Run the Launch the J-Link GDB Server program and configure using UI. 
88 #### OpenOCD
90 ##### Windows
92 STM32F103 targets
94     "C:\Program Files (x86)\UTILS\openocd-0.8.0\bin-x64\openocd-x64-0.8.0.exe" -f interface/stlink-v2.cfg -f target/stm32f1x_stlink.cfg
96 STM32F30x targets
98     "C:\Program Files (x86)\UTILS\openocd-0.8.0\bin-x64\openocd-x64-0.8.0.exe" -f scripts\board\stm32f3discovery.cfg
99     
100 ##### OSX/Linux
102 STM32F30x targets
104       openocd -f /usr/share/openocd/scripts/board/stm32vldiscovery.cfg